<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="com.rbcs.base.company.CompanyHelp" %>    
<%@include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@include file="/common/extjs.jsp" %>
<%@include file="/common/meta.jsp"%>
<%@include file="/common/validator.jsp"%>
<link href="${ctx}/styles/treeSelect.css" type='text/css' rel='stylesheet'>
<style type="text/css">
.item {
	font-size: 12px;
	line-height: 25px;
}

.warn {
	color: red;
}

.inputWidth {
	width: : 250px;
}
</style>
<title>编辑用户</title>
</head>
<body>
<div class="x-panel">
<div class="x-panel-header">用户管理</div>
<s:form action="user/save" id="save" validate="true" method="post">
<div align="center" style="margin: 20px au">
	<fieldset style="margin:10px auto; width: 600px;">
	  <legend>用户信息编辑</legend>
	  <%@ include file="/common/messages.jsp"%>
	  <s:hidden name="model.id" id="uId" />
	  <s:hidden name="selfEdit" />
	  <table width="600" border="0" cellspacing="0" style="line-height:30px; margin: 10px;">
	    <tr>
	      <td width="100" align="right">所属部门：</td>
	      <td width="500">
	        <table>
	          <tr>
	            <td>
			        <div id='comboxWithTree'></div>
	            </td>
	            <td>
			        <span id="deptmsg" class="warn"></span>&nbsp;
	            	<span class="warn">*</span>
	            </td>
	          </tr>
	        </table>
			<input type="hidden" id="parentDeptId" name="parentDeptId" class="dept" value="${model.dept.id}"/>
	      </td>
	    </tr>
	    <tr>
	      <td align="right">用户名：</td>
	      <td>
	        <s:textfield name="model.loginId" id="loginId" cssStyle="width:180px" maxlength="14" cssClass="required loginId loginIdUnique"/>
			<span class="warn">*</span>&nbsp;&nbsp;
			<s:radio list="typeMap" name="model.type" cssStyle="border:0px;" />
		  </td>
	    </tr>
	    <tr>
	      <td align="right">密　码：</td>
	      <td>
	        <s:password name="model.password" id="pwd" cssStyle="width:180px" maxlength="14" cssClass="required pwd"/>
	        <span class="warn">*</span>&nbsp;&nbsp;
	        <span>密码长度6～14位</span>
	      </td>
	    </tr>
	    <tr>
	      <td align="right">确认密码：</td>
	      <td>
	      	<s:password name="model.confirmPwd" id="repwd" cssStyle="width:180px" maxlength="14" cssClass="required repwd"/>
	      	<span class="warn">*</span>
	      </td>
	    </tr>
	    <tr>
	      <td align="right">姓　名：</td>
	      <td>
	        <s:textfield name="model.name" cssStyle="width:180px"  maxlength="20" cssClass="required"/>
	        <span class="warn">*</span>&nbsp;&nbsp;
	        <s:radio list="sexMap" name="model.sex" cssStyle="border:0px;" />
	      </td>
	    </tr>
	    <tr>
	      <td align="right">身份证：</td>
	      <td>
	        <s:textfield id="idCard" name="model.idCard" cssClass="required idCard" cssStyle="width:180px" maxlength="18"></s:textfield>
	        <span class="warn">*</span>
	      </td>
	    </tr>
	    <tr>
	      <td align="right">手　机：</td>
	      <td>
			<s:textfield name="model.mobile" id="mobile" cssStyle="width:180px" maxlength="18" cssClass="mobileCheck"/>
	      </td>
	    </tr>
	     <tr>
	      <td align="right">固　话：</td>
	      <td>
			<s:textfield name="model.hTel" cssStyle="width:180px" maxLength="18"/>
	      </td>
	    </tr>
	    <tr>
	      <td align="right">开户银行：</td>
	      <td>
	        <s:textfield id="idCard" name="model.bank" cssStyle="width:180px" maxlength="18"></s:textfield>
	        &nbsp;&nbsp;帐号：
	        <s:textfield id="idCard" name="model.bankAccount" cssStyle="width:180px" maxlength="18"></s:textfield>
	      </td>
	    </tr>
	  </table>
	</fieldset><br><br>
    <s:submit value="保存" cssClass="button"/>&nbsp;&nbsp; 
    <s:reset value="清空" cssClass="button"/>
</div>
</s:form>
</div>
<script type="text/javascript" src="${ctx}/pages/admin/dept/edit.js"></script>
<script type="text/javascript">
var rootName = '<%=CompanyHelp.getComName()%>';
var initValue = '${model.dept.name}';
if (initValue.length == 0){
	initValue = rootName;
}
Ext.onReady(function() {
	var dtree = new DeptTree({
		url : '/admin/dept/deptTree.do',
		rootName: rootName,
		initValue : initValue,
		el : 'comboxWithTree',
		innerTree :'inner-tree',
		onclick : function(nodeId) {
		  Ext.get('parentDeptId').dom.value = nodeId;
		}
	});
	dtree.init();	
});

//将密码设置为*
var uid = $("#uId").val();
if (uid != null && uid.length > 0){
	defPass = "*********";
    $('#pwd').val(defPass);
    $('#repwd').val(defPass);
}

$(function() {
	$.validator.addMethod("dept", function(value, element) {
		if (value == null || value.length == 0 || value == 0){
			$("#deptmsg").html("请选择部门");
			return false;
		}else{
			$("#deptmsg").html("");
			return true;
		}
    },"");
	
    //验证用户名
    $.validator.addMethod("loginId", function(value, element) { 
    	var reg = new RegExp("^([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[a-zA-Z0-9_\.\-])*$"); 
	    return reg.test(value); //首先判断非法字符
    }, "包含非法字符");
    
	$.validator.addMethod("loginIdUnique", function(value, element) {
		var exist = false;
		$.ajax({
			url: '${ctx}/security/user/checkName.do',
		 	type: 'post',
		 	async : false,
		 	dataType: 'json',
		 	data: {'model.loginId' : value, 'model.id' : uid},
		 	success: function(rst, textStatus){
		 		exist = rst.exist;
		 	}
		});
		return !exist; 
	},"用户名已存在");
	
	$.validator.addMethod("pwd", function(value, element) {
		if (value.length < 6){
			$("#pwdmsg").html("密码长度少于6位");
			return false;
  		} else {
  			$("#pwdmsg").html("");
  		}
		return true;
    },"");
	
	$.validator.addMethod("repwd", function(value, element) {
		if (value != $('#pwd').val()){
			$("#pwdmsg").html("两次输入的密码不一致");
			return false;
		} 
		$("#pwdmsg").html("");
		return true;
    },"");

	
	$.validator.addMethod("idCard", function(value, element) {
		if (value != null && value.length > 0){
			if (value.length != 15 && value.length != 18){
	  			return false;
			}
  		}
		return true;
    },"长度错误");
});

//添加jquery验证
$(document).ready(function() {
	$("#save").validate();
});

</script>
</body>
</html>